/**
 * 统一响应格式工具
 */

const successResponse = (res, data = null, message = '操作成功') => {
    return res.status(200).json({
        success: true,
        message,
        data
    });
};

const errorResponse = (res, message = '操作失败', statusCode = 400, error = null) => {
    const response = {
        success: false,
        message
    };
    
    if (process.env.NODE_ENV === 'development' && error) {
        response.error = error.message;
        response.stack = error.stack;
    }
    
    return res.status(statusCode).json(response);
};

const validationErrorResponse = (res, errors) => {
    return res.status(422).json({
        success: false,
        message: '验证失败',
        errors
    });
};

module.exports = {
    successResponse,
    errorResponse,
    validationErrorResponse
};

